<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>档案归还</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">档案名称</label>
                        <div class="layui-input-block">
                            <input type="text" id="name" placeholder="请输入" disabled  autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">档案编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="number" placeholder="请输入" disabled  autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">归还日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="guidt" id="guidt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">接收人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=guier&type=user','770px','490px');"></div>
                                <div class="tanxiannei" id="guier"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=guier&type=user','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="guier_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;


    $("#commentForm").validate({
        rules: {
            number: {required: true},
            name: {required: true},
        },
        messages:{
            number: {required: "请输入"},
            name: {required: "请输入"},
        }
    });


    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_coss_jie_gui, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                if(data.guier_info.length > 0){
                    tan_tags_init('#guier', data.guier_info);
                }


                var cossinfo = res.data.cossinfo;
                $("#number").val(cossinfo.number);
                $("#name").val(cossinfo.name);
                $("#guidt").val(data.guidt);





                render_from();
                initParseMoney();
            }
        });

        $("#upload_avatar").click(function () {
            $("#uploadfile").click();
        });

        $("#uploadfile").change(function () {
            var loading = layui.layer.load(0, {shade: 0.1});
            let fd = new FormData();
            fd.append('file', this.files[0]);
            fd.append('token', facade.getCookie('token'));
            $.ajax({
                url: server_api_name+ask_upload_avatar,
                type: "POST",
                data: fd,
                contentType: false,
                processData: false,
                dataType: "json",
                success: function (res) {
                    layui.layer.close(loading);
                    if (res.code === 2000) {
                        $("#avatar_id").val(res.data.id);
                        $("#avatar").val(res.data.encpath);
                        $("#avatar_dea").attr('src',get_file_complete(res.data.encpath)).show();
                    }else{
                        facade.error(res.data.msg);
                    }
                },
                error: function (res) {
                    layui.layer.close(loading);
                    facade.error("网络错误");
                },
            })
        });

        form.on('submit(add)', function(data){
            data.field.guier = tan_tags_getvalue("#guier", 'user');
            var validRes = $("#commentForm").valid();
            if(!data.field.guier){
                $("#guier").parents('.tanxian').addClass('tanerror');
                $('#guier_tanerror').text('请选择');
                validRes = false;
            }else{
                $("#guier").parents('.tanxian').removeClass('tanerror');
                $('#guier_tanerror').text('');
            }
            if(!validRes){return false;}


            data.field.id = param_id;
            data = parseMoney(data);
            facade.ajax({url: ask_coss_jie_gui, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });



</script>
</body>
</html>
